package Utilities;

import java.sql.Date;
import java.util.ArrayList;

import DataStorageClasses.Employee;
import DataStorageClasses.PayrollSheet;
import DataStorageClasses.TimeSheet;
import Database.DatabaseConnector;

public class PayrollCalculator 
{
	private DatabaseConnector dbConnector;
	private String businessName;
	private long employeeID;
	private ArrayList<TimeSheet> list;
	private double tax;
	private Date start;
	private Date end;
	
	public PayrollCalculator(String businessName, long employeeID, double tax, Date start, Date end)
	{
		dbConnector = new DatabaseConnector();
		
		this.businessName = businessName;
		this.employeeID = employeeID;
		this.tax = tax;
		this.start = start;
		this.end = end;
		
		list = dbConnector.getEmployeesTimeSheets(employeeID, start, end, false);
	}
	
	public PayrollSheet getPayroll()
	{
		double otHours = getOverTimeHours();
		double totalHours = getHours();
		
		Employee employee = dbConnector.getEmployee(employeeID, businessName);
		
		return new PayrollSheet(employeeID, employee.getFirstName(), employee.getLastName(), employee.getWage(), totalHours, 
				otHours, start, end, tax);
	}
	
	public double getHours()
	{
		double hours = 0;
		
		for(TimeSheet tSheet: list) {
			hours += tSheet.getHours();
		}
		
		return hours;
	}
	
	public double getOverTimeHours()
	{
		double otHours = 0;
		
		for(TimeSheet tSheet: list) {
			double hours = tSheet.getHours();
			if (hours > 8)
				otHours += hours;
		}
		
		return otHours;
	}
}
